/**
 * @description国际化使用igrid，滚动加载方式
 * @author chaowangbang
 * @since 2012-12-22
 */
Ccay.Module.define("ccay.manage.i18n", function(page, $S) {
			function resetClick(){
				$("#resetOnclick").click();
			}
			// 初始化
			page.ready = function() {
				var gridOption = {
					height : 370, // 滚动加载不能做高度自适应
					//percentWidth : true, // 列百分比显示
					customSetting: true,
					showStatus:true,// 显示数据状态
					popupStatus:true, // 有错误信息时直接pop出弹出框
					toolPanel: "#minibarPanel",
					showSwitch:true,
					fullOutTip:true,    //开启最大化退出提示
			   	    switchMode:"search",
			   	    genSearchByFilter:true,
					fullPanel: "#fullPanel",
					editMode : true, // 是否可编辑
					allowFilter: true,
					editPermission : "i18nManage:update|i18nManage:create", // 可编辑权限“|”或，“,”与
					// rowEdit : true, // 行编辑
					lazyLoad : true, // 滚动加载
					storageOp : {
						cacheData : true, // 是否缓存数据
						cacheKey : ["virtualId"]
						// 缓存key
					},
					rowRender : "rowSpan", // 列分组
					//wrap : true, // 单元格是否换行显示
					allowSort : false, // 禁用排序
					pagerOp : {
						pageInf : {
							pageSize : 50
							// 设置每次滚动加载数据条数范围
						}
					},
					columns : [
					// 百分比模式时，相加不能超过90%， 否则会错位
					{
						columnType : "select",
						multi : true
					},
					{
						field : 'i18nKey',
						width : 220,
						header : "ccay.i18n.label.key",
						rowSpan : true,
						filter: true,
						freezeable:true,
						rule : {
							required : true,
							specialch : true,
							maxlength : 50
						}
					}, {
						field : 'i18nContent',
						width : 220,
						filter: true,
						header : "ccay.i18n.label.content",
						rule : {
							required : true,
							maxlength : 1000
						}
					}, {
						field : 'i18nLanguage',
						cssName : "center",
						width : 100,
						header : "ccay.i18n.label.language",
						type : "enum",
						filter: {defaultFilters: false,enumable: true},
						editorOp : {
							conf : {
								multi : false,
								combo:false // 不可输入，只能选择
							}
						},
						format : {
							service : 'FN:ccay.manage.i18n.languageData',
							valueField : "id",
							displayField : "text"
						},
						rule : {
							required : true
						}
					}, 
					{
						field : 'creationDate',
						width : 120,
						filter: {range:true},
						type: "date",
						editable:false,
						header : "ccay.common.label.creationDate",
						content:"${#Ccay.Format.toDateBefore(data.creationDate && data.creationDate.getUTCTime())}",
						cssName:"center"
					}, {
						field : 'lastUpdateDate',
						width : 125,
						filter: {range:true},
						type: "date",
						editable:false,
						header : "ccay.common.label.lastUpdatedDate",
						content:"${#Ccay.Format.toDateBefore(data.lastUpdateDate && data.lastUpdateDate.getUTCTime())}",
						cssName:"center"
					}],
					ajax : {
						url : 'services/manage/i18n/list/range/${total}/${start}/${end}/${filter}'
					},
					operation : {
						search : {
							panel : '#searchForm'
						},
						del : {
							btn : '#btnDel',
							undoBtn : '#btnUndoDel'
						},
						insert : {
							btn : '#btnAdd',
							copy : true, // 是否复制添加
							clear : ['i18nKey','creationDate','lastUpdateDate'], // 清除id
							defaultRow : {
								'i18nLanguage' : workspaceVO.currentLanguage,
							} // 默认添加的行数据
						},
						save : {
							btn : '#btnSave',
							ajax : {
								url : "services/manage/i18n/batch"
							},
							fnBeforeSave:function(params,ajax, grid, optOp){
				    			var result = true;
								Ccay.doPut({
						 			async:false,
						 			url:"services/manage/i18n/validateForBatch",
						 			data : params,
						 			success:function(data){
						 				var message = [];
						 				if(data.LauguageI18nKeyUniqueFail){
						 					message.push("国际化KEY {0} 重复！".formatValue(data.LauguageI18nKeyUniqueFail.join(",")));
						 					result = false;
						 				}
						 				if(!result){
						 					Ccay.UI.showMessage(message.join("</br>"),'error',null, false,false);
						 				}
						 			}			
						 		});
						 		return result;
				    		}
						}
					}
				};

				$S("#i18nIgrid").igrid(gridOption);
			};

			// 语种
			page.languageData = function() {
				return Ccay.Format.getLangugaeList();
			};

			// 导出
			page.i18nExport = function() {
				var url = Ccay.Common.getFiltersUrl("services/manage/i18n/export/${filtersStr}","#i18nIgrid");
				Ccay.doGet(url, $S("#searchForm").jsonData(), function() {
					Ccay.Component.Excel.exportCallback();
				});
			};

			// 导入
			page.i18nImport = function() {
				var param = {
					uploadType : "ExcelImport",
					completeCallback : Ccay.Component.Excel.uploadCallback,
					closeDialog : true,
					query : "excelType=Manage.i18n"
				};
				Ccay.Component.openUploadDialog($i18n("ccay.common.button.import"), param);
			};
			// 导入
			page.i18nImportWithoutUpdate = function() {
				var param = {
					uploadType : "ExcelImport",
					completeCallback : Ccay.Component.Excel.uploadCallback,
					closeDialog : true,
					query : "excelType=Manage.i18n&importType=noUpdate"
				};
				Ccay.Component.openUploadDialog($i18n("ccay.common.button.import"), param);
			};
			page.downloadTemp = function() {
				location.href = "servlet/download?dlType=ExcelTemplate&excelType=Manage.i18n";
			}
			page.delRecords = function() {
				Ccay.UI.IGrid.Operation.del.remove($S("#i18nIgrid").manager(), $S("#i18nIgrid").manager().op, $S("#i18nIgrid").manager().op.operation.del, false);
			}
		});
